<template>
	<view class="container">
		<view>
			<desc-wrapper :title="title" :desc="desc"></desc-wrapper>
			<z-card>
				<view class="card-content-item">
					<text class="card-content-label_left">姓名</text>
					<view class="card-content_right">
						<view class="input-name-box">
							<input class="input-item" v-model="form.name" type="text" placeholder="请输入缘主姓名" />
						</view>
					</view>
				</view>
				<view class="card-content-item">
					<text class="card-content-label_left">性别</text>
					<view class="card-content_right">
						<uni-data-checkbox selectedColor="#4e6542" selectedTextColor="#333" v-model="form.sex"
							:localdata="genders" @change="sexChange"></uni-data-checkbox>
					</view>
				</view>
				<view class="card-content-item">
					<text class="card-content-label_left">类型</text>
					<view class="card-content_right">
						<uni-data-checkbox selectedColor="#4e6542" selectedTextColor="#333" v-model="form.type"
							:localdata="calendar" @change="lunarChange"></uni-data-checkbox>
					</view>
				</view>
				<view class="card-content-item">
					<text class="card-content-label_left">日期</text>
					<view class="card-content_right flex-row flex-wrap flex-1">
						<uni-data-select class="year" style="margin-right: 10rpx;margin-bottom: 10rpx;" :clear="false"
							v-model="form.year" :localdata="yearData" @change="yearChange"></uni-data-select>
						<uni-data-select class="time" isCustomIndicator style="margin-right: 10rpx;margin-bottom: 10rpx;" :clear="false"
							v-model="form.month" :localdata="monthData" @change="monthChange"></uni-data-select>
						<uni-data-select class="time" isCustomIndicator style="margin-right: 10rpx;margin-bottom: 10rpx;" :clear="false"
							v-model="form.day" :localdata="dayData" @change="dayChange"></uni-data-select>
						<uni-data-select class="time" isCustomIndicator  :clear="false" v-model="form.hours" style="margin-bottom: 10rpx;"
							:localdata="hourData" @change="hourChange"></uni-data-select>
					</view>
				</view>
			</z-card>
			<view class="bottom-btns">
				<view class="start-btn" @click="onClick_1">
					<text class="">立即排盘</text>
				</view>
				<!-- <view class="contact-btn"></view> -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '紫薇排盘',
				desc: '测试方法：输入您的信息，点击立即排盘，并查看排盘结果，请自行体会其中的指示。',
				form: {
					name: '',
					sex: 0, //男
					type: 0, //默认是农历
					year: Number(new Date().getFullYear()),
					month: Number(new Date().getMonth()) + 1,
					day: Number(new Date().getDate()),
					hours: Number(new Date().getHours()),
					minute: Number(new Date().getMinutes())
				},
				genders: [{
						value: 0,
						text: '男\b'
					},
					{
						value: 1,
						text: '女\b'
					}
				],
				calendar: [{
						value: 0,
						text: '农历'
					},
					{
						value: 1,
						text: '公历'
					}
				],
				yearData: [],
				monthData: [],
				dayData: [],
				hourData: [],
				fenData: []
			}
		},
		onLoad() {
			for (let i = 1910; i <= 2023; i++) {
				this.yearData.push({
					value: i,
					text: i + '年'
				})
			}

			for (let i = 1; i <= 12; i++) {
				this.monthData.push({
					value: i,
					text: i + '月'
				})
			}

			for (let i = 1; i <= 30; i++) {
				this.dayData.push({
					value: i,
					text: i + '日'
				})
			}
			for (let i = 0; i <= 23; i++) {
				this.hourData.push({
					value: i,
					text: i + '时'
				})
			}
			for (let i = 0; i <= 59; i++) {
				this.fenData.push({
					value: i,
					text: i + '分'
				})
			}
		},
		methods: {
			// tabbar切换时触发
			change1(e) {
				console.log(e)
				uni.switchTab({
					url: this.tabList[e].url
				})
			},
			yearChange() {},
			monthChange() {},
			dayChange() {},
			hourChange() {},
			fenChange() {},
			//切换性别触发
			sexChange(e) {
				this.form.sex = e.detail.value
				console.log('e:', e)
			},
			//切换农历触发
			lunarChange(e) {
				this.form.type = e.detail.value
				console.log(e)
			},
			onClick_1() {
				let that = this
				if (this.form.name == '') {
					this.$u.toast('请输入姓名')
					return
				}
				uni.request({
					url: 'https://cs.appzdm.com:3000/Bazi/zwpan',
					method: 'POST',
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: this.form,
					success: (res) => {
						uni.navigateTo({
							url: `/pages/ziweipaipan/detail?params=${JSON.stringify(res.data.data)}`
						})
					},
					fail: (error) => {
						console.error('Request Failed:', error)
					}
				})
			}
		}
	}
</script>
<style lang="scss">
	::v-deep .year .uni-select{
				width: 165rpx;
		    }
	::v-deep .time .uni-select{
			width: 115rpx;
			}
</style>